package 力扣.数组;

import java.util.HashSet;
import java.util.Set;

public class 存在重复元素217 {
    public static void main(String[] args) {
        int[] ints = {1,2,3,4,5,6,4};
        boolean b = containsDuplicate(ints);
        System.out.println(b);
    }

    /**
     * 使用 Hashset
     * @param nums
     * @return
     */
    public static boolean containsDuplicate(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        for (int x : nums) {
            if (!set.add(x)) {
                return true;
            }
        }
        return false;
    }
}
